package com.wonders.hisdoctor.station.project.vaccine.controller;

import com.wonders.his.common.utils.PageUtil;
import com.wonders.his.common.utils.validator.group.InsertGroup;
import com.wonders.hisdoctor.station.project.vaccine.service.IVaccineInfoDictService;
import com.wonders.hisdoctor.station.project.vaccine.domain.VaccineInfoDict;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.utils.validator.ValidateUtils;
import com.wonders.his.common.utils.validator.group.PrimaryGroup;
import com.wonders.his.common.utils.validator.group.SelectGroup;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccineInfoDictVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhanghaonan
 * @date 2021/06/25
 */
@Api(tags = "疫苗基本信息")
@RestController
@RequestMapping("/vaccine/vaccineinfodict")
public class VaccineInfoDictController {

    @Autowired
    private IVaccineInfoDictService vaccineInfoDictService;

    /**
     * 新增
     *
     * @param vaccineInfoDict
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("add")
    public BaseResult<Integer> add(@RequestBody VaccineInfoDict vaccineInfoDict, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineInfoDict, new Class[]{PrimaryGroup.class, InsertGroup.class});
        return BaseResult.success(vaccineInfoDictService.save(vaccineInfoDict, request));
    }

    /**
     * 修改
     *
     * @param vaccineInfoDict
     * @return
     */
    @ApiOperation("修改")
    @PostMapping("update")
    public BaseResult<Integer> update(@RequestBody VaccineInfoDict vaccineInfoDict, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineInfoDict, new Class[]{PrimaryGroup.class, InsertGroup.class});
        return BaseResult.success(vaccineInfoDictService.update(vaccineInfoDict, request));
    }

    /**
     * 主键删除
     *
     * @param vaccineInfoDict
     * @return
     */
    @ApiOperation("主键删除")
    @PostMapping("removeByKey")
    public BaseResult<Integer> delete(@RequestBody VaccineInfoDict vaccineInfoDict, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccineInfoDict, PrimaryGroup.class);
        return BaseResult.success(vaccineInfoDictService.removeById(vaccineInfoDict, request));
    }

    /**
     * 主键查询
     *
     * @param vaccineInfoDict
     * @return
     */
    @ApiOperation("主键查询")
    @PostMapping("queryByKey")
    public BaseResult<VaccineInfoDict> queryByPrimaryKey(@RequestBody VaccineInfoDict vaccineInfoDict) {
        ValidateUtils.validateEntity(vaccineInfoDict, PrimaryGroup.class);
        return BaseResult.success(vaccineInfoDictService.getById(vaccineInfoDict));
    }

    /**
     * 模糊查询
     *
     * @param vaccineInfoDict
     * @return
     */
    @ApiOperation("模糊查询")
    @PostMapping("search")
    public BaseResult<List<VaccineInfoDictVo>> search(@RequestBody VaccineInfoDict vaccineInfoDict) {
        PageUtil.startPage();
        return BaseResult.success(PageUtil.getDataTable(vaccineInfoDictService.search(vaccineInfoDict)));
    }

}